﻿namespace Optimizer
{
    using S = System;

    struct Point
    {
        public double X1;
        public double X2;

        public static Point operator -(Point a, Point b)
        {
            a.X1 -= b.X1;
            a.X2 -= b.X2;
            return a;
        }

        public static Point operator +(Point a, Point b)
        {
            a.X1 += b.X1;
            a.X2 += b.X2;
            return a;
        }

        public static Point operator *(Point a, double k)
        {
            a.X1 *= k;
            a.X2 *= k;
            return a;
        }

        public static Point operator *(double k, Point a)
        {
            a.X1 *= k;
            a.X2 *= k;
            return a;
        }

        public static Point operator /(Point a, double k)
        {
            a.X1 /= k;
            a.X2 /= k;
            return a;
        }

        public static double operator *(Point a, Point b)
        {
            return a.X1 * b.X1 + a.X2 * b.X2;
        }

        private static double Power2(double x)
        {
            return x * x;
        }

        public double Length()
        {
            return S.Math.Sqrt(Power2(this.X1) + Power2(this.X2));
        }

        public Point Norm()
        {
            return this / this.Length();
        }
    }

    /// <summary>
    /// точка и результат функции.
    /// </summary>
    struct FPoint
    {
        public Point X;
        public double Y;
    }
}
